<?php

namespace catchAdmin\permissions\tables\forms;

use Cassandra\Type;
use catchAdmin\permissions\model\Department as DepartmentModel;
use catchAdmin\permissions\model\Job;
use catchAdmin\permissions\model\Roles;
use catchAdmin\permissions\model\Professional;
use catcher\base\CatchModel;
use catcher\library\form\Form;
use FormBuilder\Factory\Elm;
use FormBuilder\UI\Elm\Components\Input;
use FormBuilder\UI\Elm\Components\Tree;

class User extends Form
{
    public function fields(): array
    {
        $rolesData = (new Roles())->dataRange()->field(['id', 'parent_id', 'role_name'])->select()->toTree();

        // TODO: Implement fields() method.
        return [
            self::input('username', '姓名')->col(self::col(12))->clearable(true)->required(),
            self::input('doctor_code', '医生编码')->col(self::col(12))->required(),
            self::cascader('department_id', '部门', [])
                ->col(self::col(12))
                ->options(
                    DepartmentModel::field(['id', 'parent_id', 'department_name'])->where('status', 1)->select()->toTree()
                )
                ->props(self::props('department_name', 'id', [
                    'checkStrictly' => true
                ]))->clearable(true)->filterable(true),

            self::cascader('other_dept', '其它子部门', [])
                ->col(self::col(12))
                ->options(
                    DepartmentModel::field(['id', 'parent_id', 'department_name'])->where('status', 1)->select()->toTree()
                )
                ->props(self::props('department_name', 'id', [
                    'checkStrictly' => true,
                    'multiple' => true
                ]))->clearable(true)->filterable(true)->attr('show-all-levels', false),

            self::email('email', '邮箱')->col(self::col(12))->clearable(true),

            self::selectMultiple('jobs', '职务', [])
                ->col(self::col(12))->options(
                    Job::where('status', Job::ENABLE)->field(['id as value', 'job_name as label'])->select()->toArray()
                )->clearable(true)->filterable(true),

            self::selectMultiple('professionals', '职称', [])
                ->col(self::col(12))->options(
                    Professional::where('status', Professional::ENABLE)->field(['id as value', 'name as label'])->select()->toArray()
                )->clearable(true)->filterable(true),
            self::input('password', '密码')->col(self::col(12))
                ->placeholder('请输入密码')->clearable(true),
            self::textarea('good_at', '擅长', '')->prop("cols", 200),
            self::textarea('introduction', '简介', '')->prop("cols", 200),




            self::cascader('roles', '角色', [])
                ->col(self::col(12))
                ->options(
                    $rolesData
                )
                ->props(self::props('role_name', 'id', [
                    'checkStrictly' => true,
                    'multiple' => false
                ]))->clearable(true)->filterable(true)->attr('show-all-levels', false),

        ];
    }

}
